package controller

import (
	"github.com/gin-contrib/sessions"
	"github.com/gin-gonic/gin"
	"go_web_learn/common"
)

// 设置
func SessionSet(c *gin.Context) {
	session := sessions.Default(c)
	session.Set("username", "chris")
	session.Options(sessions.Options{
		MaxAge: 3600, // 单位是秒
	})
	// 设置session的时候必须调用
	session.Save()
	common.ResponseSuccess(c, "设置成功")
}

// 获取
func SessionGet(c *gin.Context) {
	session := sessions.Default(c)
	get := session.Get("username")
	common.ResponseSuccess(c, get)
}
